using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace DownloadTool
{
    public class BoolToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue)
            {
                string[] colors = parameter?.ToString().Split('|') ?? new[] { "#4CAF50", "#757575" };
                string colorStr = boolValue ? colors[0] : colors.Length > 1 ? colors[1] : "#757575";
                
                try
                {
                    return new BrushConverter().ConvertFrom(colorStr);
                }
                catch
                {
                    return new SolidColorBrush(Colors.Black);
                }
            }
            
            return new SolidColorBrush(Colors.Black);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}